<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
</head>
<body>
    <div class="layui-form timo-compile">
    <form th:action="@{/app/version/save}">
        <input type="hidden" name="id" th:if="${appVersion}" th:value="${appVersion.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">需求URL</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="demand_url" placeholder="请输入需求URL" th:value="${appVersion?.demand_url}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">需求概述</label>
            <div class="layui-input-inline">
                <textarea class="layui-input" type="text" name="demand_title" placeholder="请输入需求概述" th:text="${appVersion?.demand_title}" rows="5" style="height: auto"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目开始时间</label>
            <div class="layui-input-inline">
                <input class="layui-input" readonly="readonly" type="text" id="startTime" name="start_time" placeholder="请输入项目开始时间" th:value="${#dates.format(appVersion?.start_time, 'yyyy-MM-dd')}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开发负责人</label>
            <div class="layui-input-inline">
                <div th:replace="/common/fragment :: selectTag('leader_id',${users},${appVersion?.leader_id},'id','nickname','')"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开发成员</label>
            <div class="layui-input-inline">
                <div th:replace="/common/fragment :: checkboxs('memberIds',${users},${memberIds},'id','nickname','')"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">版本名称</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="version" placeholder="请输入版本名称" th:value="${appVersion?.version}">
                修复版本：<input type="checkbox" name="hotfix_flag" value="1" th:checked="${appVersion?.hotfix_flag=='1'}" lay-skin="switch" lay-text="是|否">
            </div>
        </div>

        <div class="layui-form-item timo-finally">
            <button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
    </form>
</div>
<script th:replace="/common/template :: script"></script>
    <script type="text/javascript">
        layui.use(['laydate','jquery'],function () {
            var laydate = layui.laydate
            var $ = layui.jquery;
            laydate.render({
                elem: '#startTime'
            });
            $(document).ready(function () {
                $('input[name="version"]').focus(function () {
                    let val = $('input[name="version"]').val();
                    if(val && val.trim().length>0){
                        // console.log("输出框中有值，不能改变")
                        return;
                    }
                    let url = $('input[name="demand_url"]').val();
                    if(!(url && url.trim().length>0)){
                        // console.log("没有指定url")
                        return;
                    }
                    let id = url.replace(/.+(\d{7})/gi,'$1');
                    if(!(id && id.trim().length>0) || id=='$1'){
                        // console.log("解析出来的id不正确")
                        return;
                    }
                    // console.log('parsed id='+id);
                    let d = $('#startTime').val();
                    if(!(d && d.trim().length>0)){
                        // console.log("没有选择日期")
                        return;
                    }
                    d = d.replace(/\d{4}-(\d{2})-(\d{2})/gi,'$1$2');
                    $('input[name="version"]').val(id+'-'+d);
                });
            });
        });
    </script>
</body>
</html>